package com.xy.core.constant;

import java.io.File;
import java.net.URL;

/**
 * 地址相关
 */
public class PathUtil {

    //资源目录
    private static String baseDir = null;


    /**
     * 资源目录
     *
     * @return
     */
    public static String resourceDir() {
        if (baseDir == null) {
            URL url = PathUtil.class.getClassLoader().getResource("./application.yml");
            File applicationFile = new File(url.getPath());
            baseDir = applicationFile.getParentFile().getAbsolutePath();
        }
        return baseDir;
    }

    //输出临时目录
    private static String outDirStr = null;

    /**
     * 输出临时目录
     *
     * @return
     */
    public static String outDir() {
        if (outDirStr == null) {
            if (isWin()) {
                String desktopPath = System.getProperty("user.home") + "/Desktop";
                File desktop = new File(desktopPath);
                if (desktop != null && desktop.exists()) {
                    outDirStr = desktop.getAbsolutePath();
                } else {

                }
            } else {
                outDirStr = "/root/home/code_temp";
            }
        }
        return outDirStr;
    }

    //数据目录
    private static String dataDirStr = null;


    /**
     * 数据存储目录
     *
     * @return
     */
    public static String dataDir() {
        if (dataDirStr == null) {
            if (isWin()) {
                dataDirStr = "C:/code/builder";
            } else {
                dataDirStr = "/root/home/code_data";
            }
        }
        return dataDirStr;
    }


    /**
     * 是否是Window系统
     *
     * @return
     */
    private static boolean isWin() {
        String osName = System.getProperty("os.name");
        if (osName.startsWith("Win")) {
            return true;
        } else {
            return false;
        }
    }

}
